#Regression Modelling
#by Justin Rodgers & Jihoon Song
#March 2014

# Multilevel, All observation, Collective efficacy-family attachment interaction

model11 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+two_parents_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*collective_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com)
sum11 <- summary(model11)
sum11

# Multilevel, All observation, Collective efficacy-family attachmen interaction, with collective efficacy 2 variable
model11.a <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+two_parents_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*collective2_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com)
sum11.a <- summary(model11.a)
sum11.a

# Test of Triple interacion
model11.1 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+two_parents_c*fam_attach_c*collective_c+(1+two_parents_c+fam_attach_c|nc),
                 family = binomial("logit"), final_com)
sum11.1 <- summary(model11.1)
sum11.1

# Adding factor analysis and grand mean centering
final_com2 <- merge(final_com, cmsc.chct, by="nc")
final_com2$chct_fac_c <- scale(final_com2$chct_fac, center=TRUE, scale=FALSE)
final_com3 <- merge(final_com2, cmsc.chcp, by="nc")
final_com3$chcp_fac_c <- scale(final_com3$chcp_fac, center=TRUE, scale=FALSE)

cor(final_com3$collective_c,final_com3$chct_fac_c)

# Multilevel,  999obs, Cohesion/control factor analysis-family attachment interaction
model12 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+two_parents_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*chct_fac_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com2)
sum12 <- summary(model12)
sum12

# Multilevel,  999obs, Cohesion/capital factor analysis-family attachment interaction
model13 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+two_parents_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*chcp_fac_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com3)
sum13 <- summary(model13)
sum13

# Multilevel, All observation, Cohsion/capital factor analysis without interaction
model14 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+two_parents_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c+chcp_fac_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com3)
sum14 <- summary(model14)
sum14

# Subsetting the data 1
final_com4 <- subset(final_com3,two_parents==1)
final_com5 <- subset(final_com3,two_parents==0)

# Multilevel, Two Parents==1 among 999obs, Collective efficacy-family attachment interaction
model15 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*collective_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com4)
sum15 <- summary(model15)
sum15

# Multilevel, Two Parents==0 among 999obs, Collective efficacy-family attachment interaction
model16 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*collective_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com5)
sum16 <- summary(model16)
sum16

Subsetting the data 2
final_com6 <- subset(final_com,two_parents==1)
final_com7 <- subset(final_com,two_parents==0)

# Multilevel, Two Parents==1 among all obs, Collective efficacy-family attachment interaction
model17 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*collective_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com6)
sum17 <- summary(model17)
sum17

# Multilevel, Two Parents==0 among all obs, Collective efficacy-family attachment interaction
model18 <- glmer(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                 +CPOV90_c+CFORBORN_c+fam_attach_c*collective_c+(1+fam_attach_c|nc),
                 family = binomial("logit"), final_com7)
sum18 <- summary(model18)
sum18



# Logit, Two Parents==1 among all obs, Only family attachment
model19 <- glm(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                   depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
                   +fam_attach_c,
                 family = binomial("logit"), final_com6)
sum19 <- summary(model19)
sum19

# Logit, Two Parents==0 among all obs, Only family attachment
model20 <- glm(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                 depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
               +fam_attach_c,
               family = binomial("logit"), final_com7)
sum20 <- summary(model20)
sum20

# Logit, All obs, Only family attachment
model21 <- glm(suicide ~ female_c+age_c+black_c+hispanic_c+mom_edu_c+sibs_c+res_yrs_c+
                 depression_c+emotionality_c+impulsivity_c+sociability_c+sub_abuse_c+exp_suic_c
               +fam_attach_c,
               family = binomial("logit"), final_com)
sum21 <- summary(model21)
sum21

cor(final_com$two_parents,final_com$fam_attach)
cor(final_com$two_parents,final_com$black)
cor(final_com$two_parents,final_com$age)
cor(final_com$black,final_com$age)

